package jp.co.redfox.archclub.poker.hand;

import java.util.ArrayList;
import java.util.List;

import jp.co.redfox.archclub.poker.Card;
import jp.co.redfox.archclub.poker.Hand;

public class Straight implements HandRestriction {
    List<String> cardNumRank = new ArrayList<>();
    {
        cardNumRank.add("A");
        cardNumRank.add("2");
        cardNumRank.add("3");
        cardNumRank.add("4");
        cardNumRank.add("5");
        cardNumRank.add("6");
        cardNumRank.add("7");
        cardNumRank.add("8");
        cardNumRank.add("9");
        cardNumRank.add("10");
        cardNumRank.add("J");
        cardNumRank.add("Q");
        cardNumRank.add("K");
        cardNumRank.add("A");
    }

    @Override
    public boolean matches(Hand hand) {
        List<Card> cards = new ArrayList<>();
        cards.addAll(hand.getCards());

        Card.sort(cards);

        if (new RoyalStraight().matches(hand))
            return true;

        int begin = cardNumRank.indexOf(cards.get(0).getNumber());
        int limit = begin + (cardNumRank.size() - begin > 5 ? 5 : cardNumRank.size() - begin);
        
        for (int index = begin; index < limit; index++, begin++)
            if (!cardNumRank.get(begin).equals(cards.get(index).getNumber()))
                return false;
        return true;
    }

    @Override
    public int getRequiredNumber(Hand hand) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Card[] getChangeCards(Hand hand) {
        // TODO Auto-generated method stub
        return null;
    }
}
